<?php
namespace Admin\Controller;
use Think\Controller;
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
/**
 *
 */
class TestController extends Controller
{

  public function index(){
      $config = array(
        'Secret_Key' => 'KRngBBE8dEI2anOGNpeQvOtlKoogcMaNmx7mU_tq',
        'Access_Key' => '1jHOvCW0icxZff4yAlzmV8QjaJppCPjPbQNBkq_X',
        'domain' => 'om2gkku12.bkt.clouddn.com',
        'Bucket_Name' => 'feiyangergogogo'
      );
      Vendor('qiniu.autoload');
      $accessKey = $config['Access_Key'];
      $secretKey = $config['Secret_Key'];
      // 构建鉴权对象
      $auth = new Auth($accessKey, $secretKey);
      // 要上传的空间
      $bucket = $config['Bucket_Name'];
      // 生成上传 Token
      $token = $auth->uploadToken($bucket);
      // 要上传文件的本地路径
      $filePath = './index.php';
      // 上传到七牛后保存的文件名
      $key = 'index.php';
      // 初始化 UploadManager 对象并进行文件的上传。
      $uploadMgr = new UploadManager();
      // 调用 UploadManager 的 putFile 方法进行文件的上传。
      list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
      echo "\n====> putFile result: \n";
      if ($err !== null) {
          var_dump($err);
      } else {
          var_dump($ret);
      }
    }
    public function upload(){
      // $obj =new \Think\Qiniu();
      // $res = $obj->upload('img.jpg','./upload/2017/02/24/58afac68b6211.jpg');
      // // $res = $obj->downloadToken('http://olhzg90fe.bkt.clouddn.com/img.jpg');
      // print_r($res);
      $res = D('Uploads')->qiniuUpload();
      var_dump($res);
      $this->display();
    }
}
